package cp3120.ucm.client;

import cp3120.ucm.*;
import cp3120.dao.DAOFactory;
import cp3120.dao.remote.RemoteDAOFactory;
import cp3120.net.AirportClient;
import cp3120.view.MainUIProxy;
import cp3120.view.RealMainUI;
import javax.swing.UIManager;

/**
 *
 * @author Adam Scarr
 * @since r1
 * PRECONDITION: A request to start the client has been made<br>
 * POST-CONDITION: The system displays the main UI <br>
 * 1. System makes a connection the server<br>
 * 2. System gets the factory to handle requests to the server<br>
 * 3. Syetem creates a loading UI while server is connected to<br>
 * 4. Syetem creates the main UI<br>
 * 1a. System could not connect to the db and displays an error
 */

public class UCStartClient implements UCController {

    /**
     * Client entry point
     * @param args arguements passed in
     */
    public static void main(String[] args) {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception ignore) {}  // Seriously sun, 5 exceptions for somthing this meaningless?????

        new UCStartClient().run();
    }

    /**
     * runs this US
     */
    public void run() {

        AirportClient.getInstance().connect("localhost", 7778);

        if (!AirportClient.getInstance().isConnected()) {
            System.out.println("Unable to reach the server, please try again later.");
            System.exit(0);
        }

        DAOFactory.setFactory(new RemoteDAOFactory(AirportClient.getInstance()));

        new MainUIProxy(new RealMainUI());
    }
}
